package interceptor

import (
	"context"
	"google.golang.org/grpc"
	"log"
	"time"
)

// 实现 unary interceptors
func OrderUnaryServerInterceptor(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
	// 执行前
	s := time.Now()

	//执行rpc
	m, err := handler(ctx, req)

	// 执行后
	log.Printf("Method: %s, req: %s, resp: %s, latency: %s\n",
		info.FullMethod, req, m, time.Now().Sub(s))

	return m, err
}
